<template>
	<view class="orderRefund-content">
		<view class="orderRefund-box">
			<view class="order-box">
				<view>订单号</view>
				<view>{{formData.orderNo}}</view>
			</view>
			<view class="reason-box">
				<view class="reason-title">
					上传入住合同
				</view>
				<view>
					<u-upload ref="uUpload" upload-text='' @on-uploaded="onSuccess" on-choose-complete="showLoading"
						:action="action" :auto-upload="true"></u-upload>
				</view>
			</view>
			<view class="tips-box">
				注意：如果你是<text>押1付3</text>或者<text>押1付6</text>或者<text>押1付12</text>请上传补充资料<br>
				1、请要求中介或房东提供<text>《房屋房产证》</text>或<text>《房产证上原户主本人身份证信息》</text><br>
				2、如果中介或房东无法提供上述材料，将会有经济损失风险，建议更换房源申请退款。<br>
				<text>3、如继续上传非要求补充材料，所有损失用户自行承担。</text>
			</view>
		</view>
		<view class="submit-btn">
			<u-button type="primary" shape="circle" @click="submit">提交入住</u-button>
		</view>
	</view>
</template>

<script>
	import {
		OrderCheckIn
	} from "@/api/index.js"
	export default {
		data() {
			return {
				action: 'https://aiyouzixun.top/prod-api/api/v1/alioss/upload',
				formData: {
					orderNo: '',
					contractUrl: ''
				}
			}
		},
		onLoad(op) {
			this.formData.orderNo = op.orderNo
			this.sku = op.orderSku
		},
		methods: {
			showLoading() {
				console.log('showloading');
			},
			onSuccess(data) {
				uni.showLoading({
					title: '上传中...'
				})
				let that = this
				let files = [];
				files = that.$refs.uUpload.lists.filter(val => {
					return val.progress == 100;
				})
				if (files.length != 0) {
					let images = []
					files.forEach(ele => {
						images.push(ele.response.data[0].url)
					})
					that.formData.contractUrl = images.join()
					console.log(images, 'images');
				}
				setTimeout(() => {
					uni.hideLoading()
				}, 1000)
				console.log(that.formData.contractUrl, 'that.formData.images');
				// this.isUploadSuccess = true
			},
			submit() {
				let that = this
				if (that.formData.contractUrl == '') {
					uni.showModal({
						title: '提示',
						content: '未上传合同或图片未上传完成，请等待3秒后再次提交',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})
					return
				}
				if (that.sku == '签1年押1付3' || that.sku == '签1年押1付6' || that.sku == '签1年押1付12') {
					uni.showModal({
						title: '提示',
						content: `注意：你所签订的房源租期为：${that.sku},请补充资料上传房产证或户主身份证`,
						cancelText: '提交入住',
						// cancelColor: '#007aff',
						confirmText: '返回编辑',
						// confirmColor: '#000',
						success: function(res) {
							if (res.confirm) {} else if (res.cancel) {
								OrderCheckIn(that.formData).then(res => {
									uni.showToast({
										title: '入住成功！',
										duration: 800
									})
									setTimeout(() => {
										uni.navigateBack()
									}, 1000)
								})
							}
						}
					})
				} else {
					OrderCheckIn(that.formData).then(res => {
						uni.showToast({
							title: '入住成功！',
							duration: 800
						})
						setTimeout(() => {
							uni.navigateBack()
						}, 1000)
					})
				}

			}
		}
	}
</script>

<style lang="scss">
	.order-box {
		width: 95%;
		margin: 20rpx auto;
		background-color: #fff;
		border-radius: 10rpx;
		display: flex;
		padding: 15rpx 20rpx;
		justify-content: space-between;
	}

	.reason-box {
		width: 95%;
		margin: 20rpx auto;
		background-color: #fff;
		border-radius: 10rpx;
		padding: 15rpx 20rpx;

		.reason-title {
			margin-bottom: 10rpx;
			font-size: 34rpx;
			font-weight: bold;
		}
	}

	.submit-btn {
		width: 95%;
		position: fixed;
		bottom: 30rpx;
		left: 2.5%;

	}

	.tips-box {
		font-size: 30rpx;
		line-height: 2;
		width: 95%;
		margin: 20rpx auto;

		>text {
			color: #aa0000;
		}
	}
</style>